import * as constants from './constants'

const _list = ( data ) => ({
  type: constants.HOME_LIST,
  payload: data
})

export const list = () => {
  //http://47.95.113.63/ssr/api/news.json?secret=M5s2sPneDE
  //浏览器端 /api/news.json === http://localhost:3000/api/news.json
  //服务器端 /api/news.json === 根目录/api/news.json
  //需要进行区分
  return (dispatch, getState, instanceAxios) => {
    return instanceAxios.get('/api/news.json?secret=M5s2sPneDE')//由node进行一次代理
    .then(res => {
      if (res.status === 200) {
        dispatch(_list(res.data.data))
      }
    }).catch(err => {
      console.log('请求失败', err)
    })
  }
}